package com.example.demo.service.impl;

import com.example.demo.bean.Goods;
import com.example.demo.bean.Order;
import com.example.demo.bean.ShoppingCart;
import com.example.demo.bean.User;
import com.example.demo.bean.view.GoodsView;
import com.example.demo.mapper.GoodsMapper;
import com.example.demo.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service("GoodsService")
public class GoodsServiceImpl implements GoodsService {
    @Autowired(required=true)
    @Qualifier("GoodsMapper")
    private GoodsMapper goodsMapper;
    @Override
    public boolean insertGoods(Goods goods) {
        return goodsMapper.insertGoods(goods.getGoodsNum(), goods.getSellerNum(), goods.getGoodsType(), goods.getGoodsName(), goods.getImagUrl(), goods.getGoodsIntroduction(), goods.getPrice());
    }

    @Override
    public boolean deleteGoods(Goods goods) {
        return goodsMapper.deleteGoodsById(goods.getGoodsNum());
    }

    @Override
    public boolean updateGoods(Goods preGoods, Goods laGoods) {
        System.out.println(preGoods.getGoodsNum());
        return goodsMapper.updateGoods(preGoods.getGoodsNum(), laGoods.getGoodsType(), laGoods.getGoodsName(), laGoods.getImagUrl(), laGoods.getGoodsIntroduction(), laGoods.getPrice());
    }

    @Override
    public List<Goods> findAllGoods() {
        List<Goods> goodsList = goodsMapper.findAllGoods();
        if(goodsList != null)
            return goodsList;
        else
        {
            return null;
        }
    }

    @Override
    public List<GoodsView> findGoodsByOwner(User user) {
        List<GoodsView> goodsViewList = goodsMapper.findGoodsByOwner(user.getUserNum());
        if(goodsViewList != null)
            return goodsViewList;
        else
            return null;
    }

    @Override
    public GoodsView findGoodsById(String goodsNum) {
        GoodsView goodsView = goodsMapper.findGoodsById(goodsNum);
        if(goodsView != null)
            return goodsView;
        else
        {
            return null;
        }
    }

    @Override
    public List<GoodsView> findGoodsByName(String goodsName) {
        List<GoodsView> goodsViewList = goodsMapper.findGoodsByName(goodsName);
        if(goodsViewList != null)
        {
            return goodsViewList;
        }
        else
        {
            return null;
        }

    }

    @Override
    public List<GoodsView> findAllGoodsView() {
        List<GoodsView> goodsViewList = goodsMapper.findAllGoodsView();
        if(goodsViewList != null)
        {
            return goodsViewList;
        }
        else
            return null;
    }


}
